package com.nsl.my_youlai.mystar;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONWriter;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ser.DefaultSerializerProvider;

public class NslUtilPrinter {
    public static void printWithFastJsonPrettyAndNUll(Object o){
        printWithFastJsonPrettyAndNUll(o,"");
    }
    public static void printWithFastJsonPrettyAndNUll(Object o, String sectionHead){
        printHorizontal(sectionHead);
        System.out.println(JSON.toJSONString(o, JSONWriter.Feature.PrettyFormat, JSONWriter.Feature.WriteMapNullValue));
    }

    public static void printWithJacksonPretty(Object object,String sectionHead) throws JsonProcessingException {
        printHorizontal(sectionHead);
        ObjectMapper objectMapper=new ObjectMapper();
        String json=objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(object);
        System.out.println(json);
    }

    public static void printWithJacksonPretty(Object object) throws JsonProcessingException {
     printWithJacksonPretty(object,"");
    }


    public static void printHorizontal(String sectionHead){
        if(sectionHead==null || sectionHead.equals("")){
            printHorizontal();
        }else {
            System.out.println("***********************  " + sectionHead + "  *******************************");
        }
    }

    public static void printHorizontal(){
        System.out.println("******************************************************");
    }
}
